/**********************************************************
 *电子展览网JS
 *@author Vernon.Chen
 ***********************************************************/

(function($){
	$.fn.elexconClick = function(account) {
		var htmlStr = ['<div class="alert_login_form">',
		               '	<h3 name="elexcon-tip">',
		               '		<a target="blank" href="http://www.elexcon.com">电子展览网</a>用户及往届注册观众 可直接登录,无需再注册',
		               '	</h3>',
		               '	<div>',
		               '		<label>',
		               '			<span>账号：</span>',
		               '			<input type="text" name="elexcon-userName" name="user.userLoginNum" class="login_text" value="' + (account != null ? account : "") + '"/>',
		               '		</label>',
		               '		<label>',
		               '			<span>密码：</span>',
		               '			<input name ="elexcon-password" type="password" name="user.passwd" value="" autocomplete="off" class="login_text" />',
		               '		</label>',
		               '		<label class="forget_psw">',
		               '			<a href="' + basePath + 'users/token!skip.action?accountType=elexcon" target="_temp" class="forget_psw">忘记密码？</a>',
		               '			<span>&nbsp;</span>',
		               '			<input type="checkbox" name="elexcon-rememberme" value="true" checked="checked">记住我',
		               '		</label>',
		               '		<label>',
		               '			<span>&nbsp;</span>',
		               '			<input name="elexcon-login" type="button" tabindex="4" class="login_sub" value="" name="button">',
		               '		</label>',
		               '	</div>',
		               '</div>',
		              ].join('');

		new CommonAlert({html:htmlStr,scroll:true,move:false});
		// 如果是Ajax登录
		var href = window.location.href ;
		if (href.indexOf("party") > -1) {
			$("input[name='elexcon-login']").after('\
					<a name="elexcon-back" href="javascript:;" class="back_link" onmousedown="DZQCheckForUser(location.href);">返回</a>\
					');
		}
		this.elexconLogin();
	};
	
	$.fn.elexconLogin = function(){
		$("input[name='elexcon-login']").bind("click", function(){
			var url = basePath + 'users/loginAction!ajaxLogin.action';
			var postData = {
				redirectAction:$("input[name='redirectAction']").val(),
				loginType:"elexcon",
				rememberme:$("input[name='elexcon-rememberme']").prop('checked'),
				"user.userLoginNum":$("input[name='elexcon-userName']").val(),
				"user.passwd":$("input[name='elexcon-password']").val()
			};
			$.post(url, postData, function(data){
				if (data.loginSuccess) {
					if (data.redirectAction != null) {
						window.location.href = basePath + data.redirectAction;
					} else {
						window.location.href = basePath + 'home/home.action';
					}
				} else {
					// 失败
					$("div.alert_login_form h3[name='elexcon-tip']").text(data.messages).css("color","red");; 
					$("input[name='elexcon-password']").val("");
				}	
			},'json');
		});
	};
		
})(jQuery);